#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <ctime>

void print(const boost::system::error_code &, boost::asio::deadline_timer *t, int *count)
{
    if (*count < 5)
    {
        std::cout << std::clock() << " hello world! " << *count << std::endl;
        ++(*count);
        t->expires_at(t->expires_at() + boost::posix_time::seconds(1));
        t->async_wait(std::bind(print, std::placeholders::_1, t, count));
    }
}

int main(int argc, char const *argv[])
{
    boost::asio::io_service     io;
    int                         count = 0;
    boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
    t.async_wait(std::bind(print, std::placeholders::_1, &t, &count));
    std::cout << std::clock() << std::endl;
    io.run();
    std::cout << std::clock() << std::endl;
    std::cout << "Final count is " << count << std::endl;
    return 0;
}